home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / xampp-win32-1.6.5-installer.exe / phpMyAdmin / libraries / select_lang.lib.php < prev    next >
Encoding:
PHP Script  |  2007-12-20  |  22.4 KB  |  455 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  * phpMyAdmin Language Loading File
  5.  *
  6.  * @version $Id: select_lang.lib.php 10895 2007-11-02 16:45:49Z lem9 $
  7.  */
  8.  
  9. /**
  10.  * trys to find the language to use
  11.  *
  12.  * @uses    $GLOBALS['cfg']['lang']
  13.  * @uses    $GLOBALS['cfg']['DefaultLang']
  14.  * @uses    $GLOBALS['lang_failed_cfg']
  15.  * @uses    $GLOBALS['lang_failed_cookie']
  16.  * @uses    $GLOBALS['lang_failed_request']
  17.  * @uses    $_REQUEST['lang']
  18.  * @uses    $_COOKIE['pma_lang']
  19.  * @uses    $_SERVER['HTTP_ACCEPT_LANGUAGE']
  20.  * @uses    $_SERVER['HTTP_USER_AGENT']
  21.  * @uses    PMA_langSet()
  22.  * @uses    PMA_langDetect()
  23.  * @uses    explode()
  24.  * @return  bool    success if valid lang is found, otherwise false
  25.  */
  26. function PMA_langCheck()
  27. {
  28.     // check forced language
  29.     if (! empty($GLOBALS['cfg']['Lang'])) {
  30.         if (PMA_langSet($GLOBALS['cfg']['Lang'])) {
  31.             return true;
  32.         } else {
  33.             $GLOBALS['lang_failed_cfg'] = $GLOBALS['cfg']['Lang'];
  34.         }
  35.     }
  36.  
  37.     // Don't use REQUEST in following code as it might be confused by cookies with same name
  38.     // check user requested language (POST)
  39.     if (! empty($_POST['lang'])) {
  40.         if (PMA_langSet($_POST['lang'])) {
  41.             return true;
  42.         } elseif (!is_string($_POST['lang'])) {
  43.             /* Faked request, don't care on localisation */
  44.             $GLOBALS['lang_failed_request'] = 'Yes';
  45.         } else {
  46.             $GLOBALS['lang_failed_request'] = $_POST['lang'];
  47.         }
  48.     }
  49.  
  50.     // check user requested language (GET)
  51.     if (! empty($_GET['lang'])) {
  52.         if (PMA_langSet($_GET['lang'])) {
  53.             return true;
  54.         } elseif (!is_string($_GET['lang'])) {
  55.             /* Faked request, don't care on localisation */
  56.             $GLOBALS['lang_failed_request'] = 'Yes';
  57.         } else {
  58.             $GLOBALS['lang_failed_request'] = $_GET['lang'];
  59.         }
  60.     }
  61.  
  62.     // check previous set language
  63.     if (! empty($_COOKIE['pma_lang'])) {
  64.         if (PMA_langSet($_COOKIE['pma_lang'])) {
  65.             return true;
  66.         } elseif (!is_string($_COOKIE['lang'])) {
  67.             /* Faked request, don't care on localisation */
  68.             $GLOBALS['lang_failed_request'] = 'Yes';
  69.         } else {
  70.             $GLOBALS['lang_failed_cookie'] = $_COOKIE['pma_lang'];
  71.         }
  72.     }
  73.  
  74.     // try to findout user's language by checking its HTTP_ACCEPT_LANGUAGE variable
  75.     if (PMA_getenv('HTTP_ACCEPT_LANGUAGE')) {
  76.         foreach (explode(',', PMA_getenv('HTTP_ACCEPT_LANGUAGE')) as $lang) {
  77.             if (PMA_langDetect($lang, 1)) {
  78.                 return true;
  79.             }
  80.         }
  81.     }
  82.  
  83.     // try to findout user's language by checking its HTTP_USER_AGENT variable
  84.     if (PMA_langDetect(PMA_getenv('HTTP_USER_AGENT'), 2)) {
  85.         return true;
  86.     }
  87.  
  88.     // Didn't catch any valid lang : we use the default settings
  89.     if (PMA_langSet($GLOBALS['cfg']['DefaultLang'])) {
  90.         return true;
  91.     }
  92.  
  93.     return false;
  94. }
  95.  
  96. /**
  97.  * checks given lang and sets it if valid
  98.  * returns true on success, otherwise flase
  99.  *
  100.  * @uses    $GLOBALS['available_languages'] to check $lang
  101.  * @uses    $GLOBALS['lang']                to set it
  102.  * @param   string  $lang   language to set
  103.  * @return  bool    success
  104.  */
  105. function PMA_langSet(&$lang)
  106. {
  107.     if (!is_string($lang) || empty($lang) || empty($GLOBALS['available_languages'][$lang])) {
  108.         return false;
  109.     }
  110.     $GLOBALS['lang'] = $lang;
  111.     return true;
  112. }
  113.  
  114. /**
  115.  * Analyzes some PHP environment variables to find the most probable language
  116.  * that should be used
  117.  *
  118.  * @param   string   string to analyze
  119.  * @param   integer  type of the PHP environment variable which value is $str
  120.  *
  121.  * @return  bool    true on success, otherwise false
  122.  *
  123.  * @global  $available_languages
  124.  *
  125.  * @access  private
  126.  */
  127. function PMA_langDetect(&$str, $envType)
  128. {
  129.     if (empty($str)) {
  130.         return false;
  131.     }
  132.     if (empty($GLOBALS['available_languages'])) {
  133.         return false;
  134.     }
  135.  
  136.     foreach ($GLOBALS['available_languages'] as $lang => $value) {
  137.         // $envType =  1 for the 'HTTP_ACCEPT_LANGUAGE' environment variable,
  138.         //             2 for the 'HTTP_USER_AGENT' one
  139.         $expr = $value[0];
  140.         if (strpos($expr, '[-_]') === FALSE) {
  141.             $expr = str_replace('|', '([-_][[:alpha:]]{2,3})?|', $expr);
  142.         }
  143.         if (($envType == 1 && eregi('^(' . $expr . ')(;q=[0-9]\\.[0-9])?$', $str))
  144.             || ($envType == 2 && eregi('(\(|\[|;[[:space:]])(' . $expr . ')(;|\]|\))', $str))) {
  145.             if (PMA_langSet($lang)) {
  146.                 return true;
  147.             }
  148.         }
  149.     }
  150.  
  151.     return false;
  152. } // end of the 'PMA_langDetect()' function
  153.  
  154. /**
  155.  * @global string  path to the translations directory
  156.  */
  157. $GLOBALS['lang_path'] = './lang/';
  158.  
  159. /**
  160.  * @global string  interface language
  161.  */
  162. $GLOBALS['lang'] = 'en-iso-8859-1';
  163. /**
  164.  * @global boolean wether loading lang from cfg failed
  165.  */
  166. $GLOBALS['lang_failed_cfg'] = false;
  167. /**
  168.  * @global boolean wether loading lang from cookie failed
  169.  */
  170. $GLOBALS['lang_failed_cookie'] = false;
  171. /**
  172.  * @global boolean wether loading lang from user request failed
  173.  */
  174. $GLOBALS['lang_failed_request'] = false;
  175. /**
  176.  * @global string text direction ltr or rtl
  177.  */
  178. $GLOBALS['text_dir'] = 'ltr';
  179.  
  180. /**
  181.  * All the supported languages have to be listed in the array below.
  182.  * 1. The key must be the "official" ISO 639 language code and, if required,
  183.  *    the dialect code. It can also contain some informations about the
  184.  *    charset (see the Russian case).
  185.  * 2. The first of the values associated to the key is used in a regular
  186.  *    expression to find some keywords corresponding to the language inside two
  187.  *    environment variables.
  188.  *    These values contains:
  189.  *    - the "official" ISO language code and, if required, the dialect code
  190.  *      also ('bu' for Bulgarian, 'fr([-_][[:alpha:]]{2})?' for all French
  191.  *      dialects, 'zh[-_]tw' for Chinese traditional...), the dialect has to
  192.  *      be specified as first;
  193.  *    - the '|' character (it means 'OR');
  194.  *    - the full language name.
  195.  * 3. The second values associated to the key is the name of the file to load
  196.  *    without the 'inc.php' extension.
  197.  * 4. The third values associated to the key is the language code as defined by
  198.  *    the RFC1766.
  199.  * 5. The fourth value is native name in html entities.
  200.  *
  201.  * Beware that the sorting order (first values associated to keys by
  202.  * alphabetical reverse order in the array) is important: 'zh-tw' (chinese
  203.  * traditional) must be detected before 'zh' (chinese simplified) for
  204.  * example.
  205.  *
  206.  * When there are more than one charset for a language, we put the -utf-8
  207.  * last because we need the default charset to be non-utf-8 to avoid
  208.  * problems on MySQL < 4.1.x if AllowAnywhereRecoding is FALSE.
  209.  *
  210.  * For Russian, we put 1251 first, because MSIE does not accept 866
  211.  * and users would not see anything.
  212.  */
  213. /**
  214.  * @global array supported languages
  215.  */
  216. $GLOBALS['available_languages'] = array(
  217.     'af-iso-8859-1'     => array('af|afrikaans', 'afrikaans-iso-8859-1', 'af', ''),
  218.     'af-utf-8'          => array('af|afrikaans', 'afrikaans-utf-8', 'af', ''),
  219.     'ar-win1256'        => array('ar|arabic', 'arabic-windows-1256', 'ar', 'العربية'),
  220.     'ar-utf-8'          => array('ar|arabic', 'arabic-utf-8', 'ar', 'العربية'),
  221.     'az-iso-8859-9'     => array('az|azerbaijani', 'azerbaijani-iso-8859-9', 'az', 'Azərbaycanca'),
  222.     'az-utf-8'          => array('az|azerbaijani', 'azerbaijani-utf-8', 'az', 'Azərbaycanca'),
  223.  
  224.     'becyr-win1251'     => array('be|belarusian', 'belarusian_cyrillic-windows-1251', 'be', 'Беларуская'),
  225.     'becyr-utf-8'       => array('be|belarusian', 'belarusian_cyrillic-utf-8', 'be', 'Беларуская'),
  226.     'belat-utf-8'       => array('be[-_]lat|belarusian latin', 'belarusian_latin-utf-8', 'be-lat', 'Byelorussian'),
  227.     'bg-win1251'        => array('bg|bulgarian', 'bulgarian-windows-1251', 'bg', 'Български'),
  228.     'bg-koi8-r'         => array('bg|bulgarian', 'bulgarian-koi8-r', 'bg', 'Български'),
  229.     'bg-utf-8'          => array('bg|bulgarian', 'bulgarian-utf-8', 'bg', 'Български'),
  230.     'bs-win1250'        => array('bs|bosnian', 'bosnian-windows-1250', 'bs', 'Bosanski'),
  231.     'bs-utf-8'          => array('bs|bosnian', 'bosnian-utf-8', 'bs', 'Bosanski'),
  232.     'ca-iso-8859-1'     => array('ca|catalan', 'catalan-iso-8859-1', 'ca', 'Català'),
  233.     'ca-utf-8'          => array('ca|catalan', 'catalan-utf-8', 'ca', 'Català'),
  234.     'cs-iso-8859-2'     => array('cs|czech', 'czech-iso-8859-2', 'cs', 'Česky'),
  235.     'cs-win1250'        => array('cs|czech', 'czech-windows-1250', 'cs', 'Česky'),
  236.     'cs-utf-8'          => array('cs|czech', 'czech-utf-8', 'cs', 'Česky'),
  237.     'da-iso-8859-1'     => array('da|danish', 'danish-iso-8859-1', 'da', 'Dansk'),
  238.     'da-utf-8'          => array('da|danish', 'danish-utf-8', 'da', 'Dansk'),
  239.     'de-iso-8859-1'     => array('de|german', 'german-iso-8859-1', 'de', 'Deutsch'),
  240.     'de-iso-8859-15'    => array('de|german', 'german-iso-8859-15', 'de', 'Deutsch'),
  241.     'de-utf-8'          => array('de|german', 'german-utf-8', 'de', 'Deutsch'),
  242.     'el-iso-8859-7'     => array('el|greek',  'greek-iso-8859-7', 'el', 'Ελληνικά'),
  243.     'el-utf-8'          => array('el|greek',  'greek-utf-8', 'el', 'Ελληνικά'),
  244.     'en-iso-8859-1'     => array('en|english',  'english-iso-8859-1', 'en', ''),
  245.     'en-iso-8859-15'    => array('en|english',  'english-iso-8859-15', 'en', ''),
  246.     'en-utf-8'          => array('en|english',  'english-utf-8', 'en', ''),
  247.     'es-iso-8859-1'     => array('es|spanish', 'spanish-iso-8859-1', 'es', 'Español'),
  248.     'es-iso-8859-15'    => array('es|spanish', 'spanish-iso-8859-15', 'es', 'Español'),
  249.     'es-utf-8'          => array('es|spanish', 'spanish-utf-8', 'es', 'Español'),
  250.     'et-iso-8859-1'     => array('et|estonian', 'estonian-iso-8859-1', 'et', 'Eesti'),
  251.     'et-utf-8'          => array('et|estonian', 'estonian-utf-8', 'et', 'Eesti'),
  252.     'eu-iso-8859-1'     => array('eu|basque', 'basque-iso-8859-1', 'eu', 'Euskara'),
  253.     'eu-utf-8'          => array('eu|basque', 'basque-utf-8', 'eu', 'Euskara'),
  254.     'fa-win1256'        => array('fa|persian', 'persian-windows-1256', 'fa', 'فارسی'),
  255.     'fa-utf-8'          => array('fa|persian', 'persian-utf-8', 'fa', 'فارسی'),
  256.     'fi-iso-8859-1'     => array('fi|finnish', 'finnish-iso-8859-1', 'fi', 'Suomi'),
  257.     'fi-iso-8859-15'    => array('fi|finnish', 'finnish-iso-8859-15', 'fi', 'Suomi'),
  258.     'fi-utf-8'          => array('fi|finnish', 'finnish-utf-8', 'fi', 'Suomi'),
  259.     'fr-iso-8859-1'     => array('fr|french', 'french-iso-8859-1', 'fr', 'Français'),
  260.     'fr-iso-8859-15'    => array('fr|french', 'french-iso-8859-15', 'fr', 'Français'),
  261.     'fr-utf-8'          => array('fr|french', 'french-utf-8', 'fr', 'Français'),
  262.     'gl-iso-8859-1'     => array('gl|galician', 'galician-iso-8859-1', 'gl', 'Galego'),
  263.     'gl-utf-8'          => array('gl|galician', 'galician-utf-8', 'gl', 'Galego'),
  264.     'he-iso-8859-8-i'   => array('he|hebrew', 'hebrew-iso-8859-8-i', 'he', 'עברית'),
  265.     'he-utf-8'          => array('he|hebrew', 'hebrew-utf-8', 'he', 'עברית'),
  266.     'hi-utf-8'          => array('hi|hindi', 'hindi-utf-8', 'hi', 'हिन्दी'),
  267.     'hr-win1250'        => array('hr|croatian', 'croatian-windows-1250', 'hr', 'Hrvatski'),
  268.     'hr-iso-8859-2'     => array('hr|croatian', 'croatian-iso-8859-2', 'hr', 'Hrvatski'),
  269.     'hr-utf-8'          => array('hr|croatian', 'croatian-utf-8', 'hr', 'Hrvatski'),
  270.     'hu-iso-8859-2'     => array('hu|hungarian', 'hungarian-iso-8859-2', 'hu', 'Magyar'),
  271.     'hu-utf-8'          => array('hu|hungarian', 'hungarian-utf-8', 'hu', 'Magyar'),
  272.     'id-iso-8859-1'     => array('id|indonesian', 'indonesian-iso-8859-1', 'id', 'Bahasa Indonesia'),
  273.     'id-utf-8'          => array('id|indonesian', 'indonesian-utf-8', 'id', 'Bahasa Indonesia'),
  274.     'it-iso-8859-1'     => array('it|italian', 'italian-iso-8859-1', 'it', 'Italiano'),
  275.     'it-iso-8859-15'    => array('it|italian', 'italian-iso-8859-15', 'it', 'Italiano'),
  276.     'it-utf-8'          => array('it|italian', 'italian-utf-8', 'it', 'Italiano'),
  277.     'ja-euc'            => array('ja|japanese', 'japanese-euc', 'ja', '日本語'),
  278.     'ja-sjis'           => array('ja|japanese', 'japanese-sjis', 'ja', '日本語'),
  279.     'ja-utf-8'          => array('ja|japanese', 'japanese-utf-8', 'ja', '日本語'),
  280.     'ko-euc-kr'         => array('ko|korean', 'korean-euc-kr', 'ko', '한국어'),
  281.     'ko-utf-8'          => array('ko|korean', 'korean-utf-8', 'ko', '한국어'),
  282.     'ka-utf-8'          => array('ka|georgian', 'georgian-utf-8', 'ka', 'ქართული'),
  283.     'lt-win1257'        => array('lt|lithuanian', 'lithuanian-windows-1257', 'lt', 'Lietuvių'),
  284.     'lt-utf-8'          => array('lt|lithuanian', 'lithuanian-utf-8', 'lt', 'Lietuvių'),
  285.     'lv-win1257'        => array('lv|latvian', 'latvian-windows-1257', 'lv', 'Latviešu'),
  286.     'lv-utf-8'          => array('lv|latvian', 'latvian-utf-8', 'lv', 'Latviešu'),
  287.     'mkcyr-win1251'     => array('mk|macedonian', 'macedonian_cyrillic-windows-1251', 'mk', 'Macedonian'),
  288.     'mkcyr-utf-8'       => array('mk|macedonian', 'macedonian_cyrillic-utf-8', 'mk', 'Macedonian'),
  289.     'mn-utf-8'          => array('mn|mongolian', 'mongolian-utf-8', 'mn', 'Монгол'),
  290.     'ms-iso-8859-1'     => array('ms|malay', 'malay-iso-8859-1', 'ms', 'Bahasa Melayu'),
  291.     'ms-utf-8'          => array('ms|malay', 'malay-utf-8', 'ms', 'Bahasa Melayu'),
  292.     'nl-iso-8859-1'     => array('nl|dutch', 'dutch-iso-8859-1', 'nl', 'Nederlands'),
  293.     'nl-iso-8859-15'    => array('nl|dutch', 'dutch-iso-8859-15', 'nl', 'Nederlands'),
  294.     'nl-utf-8'          => array('nl|dutch', 'dutch-utf-8', 'nl', 'Nederlands'),
  295.     'no-iso-8859-1'     => array('no|norwegian', 'norwegian-iso-8859-1', 'no', 'Norsk'),
  296.     'no-utf-8'          => array('no|norwegian', 'norwegian-utf-8', 'no', 'Norsk'),
  297.     'pl-iso-8859-2'     => array('pl|polish', 'polish-iso-8859-2', 'pl', 'Polski'),
  298.     'pl-win1250'        => array('pl|polish', 'polish-windows-1250', 'pl', 'Polski'),
  299.     'pl-utf-8'          => array('pl|polish', 'polish-utf-8', 'pl', 'Polski'),
  300.     'ptbr-iso-8859-1'   => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-iso-8859-1', 'pt-BR', 'Português'),
  301.     'ptbr-utf-8'        => array('pt[-_]br|brazilian portuguese', 'brazilian_portuguese-utf-8', 'pt-BR', 'Português'),
  302.     'pt-iso-8859-1'     => array('pt|portuguese', 'portuguese-iso-8859-1', 'pt', 'Português'),
  303.     'pt-iso-8859-15'    => array('pt|portuguese', 'portuguese-iso-8859-15', 'pt', 'Português'),
  304.     'pt-utf-8'          => array('pt|portuguese', 'portuguese-utf-8', 'pt', 'Português'),
  305.     'ro-iso-8859-1'     => array('ro|romanian', 'romanian-iso-8859-1', 'ro', 'Română'),
  306.     'ro-utf-8'          => array('ro|romanian', 'romanian-utf-8', 'ro', 'Română'),
  307.     'ru-win1251'        => array('ru|russian', 'russian-windows-1251', 'ru', 'Русский'),
  308.     'ru-cp-866'         => array('ru|russian', 'russian-cp-866', 'ru', 'Русский'),
  309.     'ru-koi8-r'         => array('ru|russian', 'russian-koi8-r', 'ru', 'Русский'),
  310.     'ru-utf-8'          => array('ru|russian', 'russian-utf-8', 'ru', 'Русский'),
  311.     'si-utf-8'          => array('si|sinhala', 'sinhala-utf-8', 'si', 'සිංහල'),
  312.     'sk-iso-8859-2'     => array('sk|slovak', 'slovak-iso-8859-2', 'sk', 'Slovenčina'),
  313.     'sk-win1250'        => array('sk|slovak', 'slovak-windows-1250', 'sk', 'Slovenčina'),
  314.     'sk-utf-8'          => array('sk|slovak', 'slovak-utf-8', 'sk', 'Slovenčina'),
  315.     'sl-iso-8859-2'     => array('sl|slovenian', 'slovenian-iso-8859-2', 'sl', 'Slovenščina'),
  316.     'sl-win1250'        => array('sl|slovenian', 'slovenian-windows-1250', 'sl', 'Slovenščina'),
  317.     'sl-utf-8'          => array('sl|slovenian', 'slovenian-utf-8', 'sl', 'Slovenščina'),
  318.     'sq-iso-8859-1'     => array('sq|albanian', 'albanian-iso-8859-1', 'sq', 'Shqip'),
  319.     'sq-utf-8'          => array('sq|albanian', 'albanian-utf-8', 'sq', 'Shqip'),
  320.     'srlat-win1250'     => array('sr[-_]lat|serbian latin', 'serbian_latin-windows-1250', 'sr-lat', 'Srpski'),
  321.     'srlat-utf-8'       => array('sr[-_]lat|serbian latin', 'serbian_latin-utf-8', 'sr-lat', 'Srpski'),
  322.     'srcyr-win1251'     => array('sr|serbian', 'serbian_cyrillic-windows-1251', 'sr', 'Српски'),
  323.     'srcyr-utf-8'       => array('sr|serbian', 'serbian_cyrillic-utf-8', 'sr', 'Српски'),
  324.     'sv-iso-8859-1'     => array('sv|swedish', 'swedish-iso-8859-1', 'sv', 'Svenska'),
  325.     'sv-utf-8'          => array('sv|swedish', 'swedish-utf-8', 'sv', 'Svenska'),
  326.     'th-tis-620'        => array('th|thai', 'thai-tis-620', 'th', 'ภาษาไทย'),
  327.     'th-utf-8'          => array('th|thai', 'thai-utf-8', 'th', 'ภาษาไทย'),
  328.     'tr-iso-8859-9'     => array('tr|turkish', 'turkish-iso-8859-9', 'tr', 'Türkçe'),
  329.     'tr-utf-8'          => array('tr|turkish', 'turkish-utf-8', 'tr', 'Türkçe'),
  330.     'tt-iso-8859-9'     => array('tt|tatarish', 'tatarish-iso-8859-9', 'tt', 'Tatarça'),
  331.     'tt-utf-8'          => array('tt|tatarish', 'tatarish-utf-8', 'tt', 'Tatarça'),
  332.     'uk-win1251'        => array('uk|ukrainian', 'ukrainian-windows-1251', 'uk', 'Українська'),
  333.     'uk-utf-8'          => array('uk|ukrainian', 'ukrainian-utf-8', 'uk', 'Українська'),
  334.     'zhtw-big5'         => array('zh[-_](tw|hk)|chinese traditional', 'chinese_traditional-big5', 'zh-TW', '中文'),
  335.     'zhtw-utf-8'        => array('zh[-_](tw|hk)|chinese traditional', 'chinese_traditional-utf-8', 'zh-TW', '中文'),
  336.     'zh-gb2312'         => array('zh|chinese simplified', 'chinese_simplified-gb2312', 'zh', '中文'),
  337.     'zh-utf-8'          => array('zh|chinese simplified', 'chinese_simplified-utf-8', 'zh', '中文'),
  338. );
  339.  
  340. // Language filtering support
  341. if (! empty($GLOBALS['cfg']['FilterLanguages'])) {
  342.     $new_lang = array();
  343.     foreach ($GLOBALS['available_languages'] as $key => $val) {
  344.         if (preg_match('@' . $GLOBALS['cfg']['FilterLanguages'] . '@', $key)) {
  345.             $new_lang[$key] = $val;
  346.         }
  347.     }
  348.     if (count($new_lang) > 0) {
  349.         $GLOBALS['available_languages'] = $new_lang;
  350.     }
  351.     unset($key, $val, $new_lang);
  352. }
  353.  
  354. /**
  355.  * first check for lang dir exists
  356.  */
  357. if (! is_dir($GLOBALS['lang_path'])) {
  358.     // language directory not found
  359.     trigger_error('phpMyAdmin-ERROR: path not found: '
  360.         . $GLOBALS['lang_path'] . ', check your language directory.',
  361.         E_USER_WARNING);
  362.     // and tell the user
  363.     PMA_fatalError('path to languages is invalid: ' . $GLOBALS['lang_path']);
  364. }
  365.  
  366. /**
  367.  * check for language files
  368.  */
  369. foreach ($GLOBALS['available_languages'] as $each_lang_key => $each_lang) {
  370.     if (! file_exists($GLOBALS['lang_path'] . $each_lang[1] . '.inc.php')) {
  371.         unset($GLOBALS['available_languages'][$each_lang_key]);
  372.     }
  373. }
  374. unset($each_lang_key, $each_lang);
  375.  
  376. /**
  377.  * @global array MySQL charsets map
  378.  */
  379. $GLOBALS['mysql_charset_map'] = array(
  380.     'big5'         => 'big5',
  381.     'cp-866'       => 'cp866',
  382.     'euc-jp'       => 'ujis',
  383.     'euc-kr'       => 'euckr',
  384.     'gb2312'       => 'gb2312',
  385.     'gbk'          => 'gbk',
  386.     'iso-8859-1'   => 'latin1',
  387.     'iso-8859-2'   => 'latin2',
  388.     'iso-8859-7'   => 'greek',
  389.     'iso-8859-8'   => 'hebrew',
  390.     'iso-8859-8-i' => 'hebrew',
  391.     'iso-8859-9'   => 'latin5',
  392.     'iso-8859-13'  => 'latin7',
  393.     'iso-8859-15'  => 'latin1',
  394.     'koi8-r'       => 'koi8r',
  395.     'shift_jis'    => 'sjis',
  396.     'tis-620'      => 'tis620',
  397.     'utf-8'        => 'utf8',
  398.     'windows-1250' => 'cp1250',
  399.     'windows-1251' => 'cp1251',
  400.     'windows-1252' => 'latin1',
  401.     'windows-1256' => 'cp1256',
  402.     'windows-1257' => 'cp1257',
  403. );
  404.  
  405. /*
  406.  * Do the work!
  407.  */
  408.  
  409. /**
  410.  * @global boolean whether charset recoding should be allowed or not
  411.  */
  412. $GLOBALS['allow_recoding'] = false;
  413. if (empty($GLOBALS['convcharset'])) {
  414.     if (isset($_COOKIE['pma_charset'])) {
  415.         $GLOBALS['convcharset'] = $_COOKIE['pma_charset'];
  416.     } else {
  417.         // session.save_path might point to a bad folder, in which case
  418.         // $GLOBALS['cfg'] would not exist
  419.         $convcharset = isset($GLOBALS['cfg']['DefaultCharset']) ? $GLOBALS['cfg']['DefaultCharset'] : 'utf-8';
  420.     }
  421. }
  422.  
  423. if (! PMA_langCheck()) {
  424.     // fallback language
  425.     $fall_back_lang = 'en-utf-8';
  426.     $line = __LINE__;
  427.     if (! PMA_langSet($fall_back_lang)) {
  428.         trigger_error('phpMyAdmin-ERROR: invalid lang code: '
  429.             . __FILE__ . '#' . $line . ', check hard coded fall back language.',
  430.             E_USER_WARNING);
  431.         // stop execution
  432.         // and tell the user that his choosen language is invalid
  433.         PMA_fatalError('Could not load any language, please check your language settings and folder.');
  434.     }
  435. }
  436.  
  437. // Defines the associated filename and load the translation
  438. $lang_file = $GLOBALS['lang_path'] . $GLOBALS['available_languages'][$GLOBALS['lang']][1] . '.inc.php';
  439. require_once $lang_file;
  440.  
  441. // now, that we have loaded the language strings we can send the errors
  442. if ($GLOBALS['lang_failed_cfg']) {
  443.     $GLOBALS['PMA_errors'][] = sprintf($GLOBALS['strLanguageUnknown'], htmlspecialchars($GLOBALS['lang_failed_cfg']));
  444. }
  445. if ($GLOBALS['lang_failed_cookie']) {
  446.     $GLOBALS['PMA_errors'][] = sprintf($GLOBALS['strLanguageUnknown'], htmlspecialchars($GLOBALS['lang_failed_cookie']));
  447. }
  448. if ($GLOBALS['lang_failed_request']) {
  449.     $GLOBALS['PMA_errors'][] = sprintf($GLOBALS['strLanguageUnknown'], htmlspecialchars($GLOBALS['lang_failed_request']));
  450. }
  451.  
  452. unset($line, $fall_back_lang,
  453.     $GLOBALS['lang_failed_cfg'], $GLOBALS['lang_failed_cookie'], $GLOBALS['ang_failed_request'], $GLOBALS['strLanguageUnknown']);
  454. ?>
  455.